package fr.mairie.parc.page.installation;

import java.util.List;

import javax.annotation.Resource;

import org.apache.click.control.Form;
import org.apache.click.control.PageLink;
import org.apache.click.dataprovider.DataProvider;
import org.apache.click.util.Bindable;
import org.springframework.context.ApplicationContext;

import fr.mairie.parc.context.AppContext;
import fr.mairie.parc.control.installation.InstallationFields;
import fr.mairie.parc.control.installation.InstallationTable;
import fr.mairie.parc.domain.Installation;
import fr.mairie.parc.page.BorderPage;
import fr.mairie.parc.service.InstallationManager;

public class InstallationPage extends BorderPage{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Resource protected InstallationManager installationManager;
	@Bindable protected InstallationTable resultTable = new InstallationTable("resultTable", this, ViewInstallationPage.class);
	@Bindable protected Form bottomButtons = new Form("bottomButtons");

	protected InstallationFields fields = new InstallationFields();

	public InstallationPage() {

		resultTable.setDataProvider(new DataProvider<Installation>() {
			private static final long serialVersionUID = 1L;
			public Iterable<Installation> getData() {
				List<Installation> res = installationManager.selectAll();
		    	return res;
		    }
		});

		PageLink validationRowLink = new PageLink("Validate", EditInstallationPage.class);
		validationRowLink.setImageSrc("/assets/images/16x16/application_form_edit.png");
		validationRowLink.setTitle("Edit Validation");
		//validationRowLink.setParameter("referrer", "list-user-dif-request.htm");

		resultTable.addActionColumnLink(validationRowLink);
	}

	@Override
	public void onInit() {
		super.onInit();
		ApplicationContext ctx = AppContext.getApplicationContext();
    	installationManager = (InstallationManager) ctx.getBean("installationManager");
	}


}

